package development.hdk.node;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.FloatMath;
import development.hdk.mindmapfornandroid.*;

public class OvalNode extends Node
{
  double a;
  int actualTextSize;
  double b;
  int borderInt;
  Rect[] bounds;
  float cx;
  float cy;
  Rect defaultBounds = new Rect();
  double deltaX;
  double deltaY;
  int dx;
  int dy;
  int focusInt;
  float h;
  private int iconPadding = 10;
  float k;
  String[] lines;
  float maxWidth;
  Rect minBounds = new Rect();
  float nx;
  float ny;
  Rect r = new Rect();
  float size;
  float totalHeight;
  double tx;
  double ty;
  float w;
  double x1;
  double x2;
  double y1;
  double y2;

  public OvalNode(Context paramContext, float paramFloat1, float paramFloat2, int paramInt, Node paramNode, Attributes paramAttributes, CommonResources paramCommonResources)
  {
    super(paramContext, paramFloat1, paramFloat2, paramInt, paramNode, paramAttributes, paramCommonResources);
  }

  public OvalNode(Context paramContext, int paramInt1, int paramInt2, int paramInt3, Node paramNode, CommonResources paramCommonResources, Attributes paramAttributes)
  {
    super(paramContext, paramInt1, paramInt2, paramInt3, paramNode, paramCommonResources, paramAttributes);
  }

  public OvalNode(Context paramContext, Node paramNode)
  {
    super(paramContext, paramNode);
  }

  public boolean doesIntersect(int paramInt1, int paramInt2)
  {
    this.a = (this.width / 2.0D);
    this.b = (this.height / 2.0D);
    this.deltaX = (paramInt1 - (this.x + this.a));
    this.deltaY = (paramInt2 - (this.y + this.b));
    if (this.deltaX * this.deltaX / (this.a * this.a) + this.deltaY * this.deltaY / (this.b * this.b) <= 1.0D)
    	return true;
    return false;
  }

  public Point getLineConnection(float paramFloat1, float paramFloat2)
  {
    this.cx = (this.x + this.width / 2.0F);
    this.cy = (this.y + this.height / 2.0F);
    this.w = (this.width / 2.0F);
    this.h = (this.height / 2.0F);
    this.w *= this.w;
    this.w = (this.h * this.h);
    this.k = 0.0F;
    if (this.cx == paramFloat1)
    {
      this.k = 2.147484E+009F;
      this.k = Math.abs(this.k);
      this.nx = FloatMath.sqrt(this.w * this.h / (this.w * this.k * this.k + this.h));
      this.ny = (this.k * this.nx);
      this.dx = 0;
      this.dy = 0;
      if (this.cx <= paramFloat1)
      this.dx = Math.round(this.cx - this.nx);
      if (this.cy <= paramFloat2)
      {
      }
    }
    label258: label277: for (this.dy = Math.round(this.cy - this.ny); ; this.dy = Math.round(this.cy + this.ny))
    {
      
      this.k = ((this.cy - paramFloat2) / (this.cx - paramFloat1));
      this.dx = Math.round(this.cx + this.nx);
      return new Point(this.dx, this.dy);
    }
  }

  public Rect getNodeBounds()
  {
    this.lines = this.text.split("\n");
    this.bounds = new Rect[this.lines.length];
    this.totalHeight = 0.0F;
    this.maxWidth = 0.0F;
    this.size = this.commonResources.getZoom();
    this.actualTextSize = (int)(30.0F * this.size);
    if (this.actualTextSize == 0)
      this.actualTextSize = 1;
    this.textPaint.setTextSize(this.actualTextSize);
    this.textPaint.getTextBounds("K|p", 0, "K|p".length(), this.defaultBounds);
    int i = 0;
    if (i >= this.bounds.length)
    {
      this.textPaint.getTextBounds("e", 0, "e".length(), this.minBounds);
      if (this.totalHeight < this.minBounds.height())
        this.totalHeight = this.minBounds.height();
      if (this.minBounds.width() > this.maxWidth)
        this.maxWidth = this.minBounds.width();
      this.borderInt = Math.round(5.0F * this.size);
      if (this.borderInt == 0)
        this.borderInt = 1;
      int j = Math.round(2.0F * this.size);
      this.focusInt = 0;
      if (this.isFocused)
        this.focusInt = this.borderInt;
      this.ty = (this.totalHeight + j * (-1 + this.bounds.length));
      this.tx = this.maxWidth;
      double d = this.iconPadding * this.size;
      if ((this.attributes.getShowIcon()) && (this.icon != null))
        this.tx = (d + (this.tx + this.bounds[0].height()));
      this.x1 = (this.tx / 2.0D);
      this.x2 = (this.tx / 2.0D + Math.round(20.0F * this.size));
      this.y1 = (this.ty / 2.0D + Math.round(10.0F * this.size));
      this.y2 = (this.ty / 2.0D);
      this.b = Math.sqrt((Math.pow(this.x2, 2.0D) * Math.pow(this.y1, 2.0D) - Math.pow(this.x1, 2.0D) * Math.pow(this.y2, 2.0D)) / (Math.pow(this.x2, 2.0D) - Math.pow(this.x1, 2.0D)));
      this.a = Math.sqrt(Math.pow(this.x1, 2.0D) * Math.pow(this.b, 2.0D) / (Math.pow(this.b, 2.0D) - Math.pow(this.y1, 2.0D)));
      this.width = ((int)Math.round(2.0D * this.a) + 2 * this.borderInt + 2 * this.focusInt);
      this.height = ((int)Math.round(2.0D * this.b) + 2 * this.borderInt + 2 * this.focusInt);
      this.r = new Rect();
      this.r.set(0, 0, this.width, this.height);
      
    }
    this.bounds[i] = new Rect();
    if ((this.lines[i].equals("")) || (this.lines[i] == null))
      this.textPaint.getTextBounds("e", 0, "e".length(), this.bounds[i]);
    while (true)
    {
      if (Math.abs(this.defaultBounds.bottom) > Math.abs(this.bounds[i].bottom))
        this.bounds[i].bottom = this.defaultBounds.bottom;
      if (Math.abs(this.defaultBounds.top) > Math.abs(this.bounds[i].top))
        this.bounds[i].top = this.defaultBounds.top;
      this.totalHeight += this.bounds[i].height();
      if (this.bounds[i].width() > this.maxWidth)
        this.maxWidth = this.bounds[i].width();
      i++;
      this.textPaint.getTextBounds(this.lines[i], 0, this.lines[i].length(), this.bounds[i]);
      break;
    }
    return this.r;
  }

  protected void onDraw(Canvas paramCanvas)
  {
    super.onDraw(paramCanvas);
    this.size = this.commonResources.getZoom();
    this.textPaint.setTextSize(30.0F * this.size);
    this.backgroundPaint.setColor(this.attributes.getBackgroundColor());
    this.borderPaint.setColor(this.attributes.getBorderColor());
    this.lines = this.text.split("\n");
    this.bounds = new Rect[this.lines.length];
    this.totalHeight = 0.0F;
    this.maxWidth = 0.0F;
    this.actualTextSize = (int)(30.0F * this.size);
    if (this.actualTextSize == 0)
      this.actualTextSize = 1;
    this.textPaint.setTextSize(this.actualTextSize);
    this.textPaint.getTextBounds("K|p", 0, "K|p".length(), this.defaultBounds);
    int i = 0;
    int j = 0;
    int i1 = 0;
    int i2 = 0;
    if (i >= this.bounds.length)
    {
      this.textPaint.getTextBounds("e", 0, "e".length(), this.minBounds);
      if (this.totalHeight < this.minBounds.height())
        this.totalHeight = this.minBounds.height();
      if (this.minBounds.width() > this.maxWidth)
        this.maxWidth = this.minBounds.width();
      this.borderInt = Math.round(5.0F * this.size);
      if (this.borderInt == 0)
        this.borderInt = 1;
      j = Math.round(2.0F * this.size);
      this.focusInt = 0;
      if (this.isFocused)
        this.focusInt = this.borderInt;
      this.ty = (this.totalHeight + j * (-1 + this.bounds.length));
      this.tx = this.maxWidth;
      float f = this.iconPadding * this.size;
      if (this.attributes.getShowIcon())
        this.tx = (this.tx + this.bounds[0].height() + f);
      this.dx = Math.round(20.0F * this.size);
      this.dy = Math.round(10.0F * this.size);
      this.x1 = (this.tx / 2.0D);
      this.x2 = (this.tx / 2.0D + this.dx);
      this.y1 = (this.ty / 2.0D + this.dy);
      this.y2 = (this.ty / 2.0D);
      this.b = Math.sqrt((Math.pow(this.x2, 2.0D) * Math.pow(this.y1, 2.0D) - Math.pow(this.x1, 2.0D) * Math.pow(this.y2, 2.0D)) / (Math.pow(this.x2, 2.0D) - Math.pow(this.x1, 2.0D)));
      double d = Math.sqrt(Math.pow(this.x1, 2.0D) * Math.pow(this.b, 2.0D) / (Math.pow(this.b, 2.0D) - Math.pow(this.y1, 2.0D)));
      int m = (int)Math.round(2.0D * d);
      int n = (int)Math.round(2.0D * this.b);
      if (this.isFocused)
        paramCanvas.drawOval(new RectF(0.0F, 0.0F, m + 2 * this.borderInt + 2 * this.focusInt, n + 2 * this.borderInt + 2 * this.focusInt), this.shadowPaint);
      paramCanvas.drawOval(new RectF(this.focusInt, this.focusInt, m + 2 * this.borderInt + this.focusInt, n + 2 * this.borderInt + this.focusInt), this.borderPaint);
      paramCanvas.drawOval(new RectF(this.borderInt + this.focusInt, this.borderInt + this.focusInt, m + (this.borderInt + this.focusInt), n + (this.borderInt + this.focusInt)), this.backgroundPaint);
      if ((this.attributes.getShowIcon()) && (this.icon != null))
      {
        int i6 = (int)Math.round((2.0D * d - this.tx) / 2.0D) + this.borderInt + this.focusInt;
        int i7 = (int)Math.round(this.b - this.bounds[0].height() / 2) + this.borderInt + this.focusInt;
        int i8 = Math.round(this.bounds[0].height());
        Bitmap localBitmap = this.icon;
        Rect localRect = new Rect(i6, i7, i6 + i8, i7 + i8);
        paramCanvas.drawBitmap(localBitmap, null, localRect, null);
      }
      if ((299 * Color.red(this.attributes.getBackgroundColor()) + 587 * Color.green(this.attributes.getBackgroundColor()) + 114 * Color.blue(this.attributes.getBackgroundColor())) / 1000 <= 100.0F){}
      this.textPaint.setColor(-16777216);
      i1 = (int)Math.round((2.0D * d - this.tx) / 2.0D) + this.borderInt + this.focusInt;
      if (this.attributes.getShowIcon())
        i1 = i1 + Math.round(f) + Math.round(this.bounds[0].height());
      i2 = (int)Math.round((2.0D * this.b - this.ty) / 2.0D) + this.borderInt + this.focusInt;
    }
    for (int i3 = 0; ; i3++)
    {
      if (i3 >= this.lines.length)
      {
        
        this.bounds[i] = new Rect();
        if ((this.lines[i].equals("")) || (this.lines[i] == null))
          this.textPaint.getTextBounds("e", 0, "e".length(), this.bounds[i]);
        while (true)
        {
          if (Math.abs(this.defaultBounds.bottom) > Math.abs(this.bounds[i].bottom))
            this.bounds[i].bottom = this.defaultBounds.bottom;
          if (Math.abs(this.defaultBounds.top) > Math.abs(this.bounds[i].top))
            this.bounds[i].top = this.defaultBounds.top;
          this.totalHeight += this.bounds[i].height();
          if (this.bounds[i].width() > this.maxWidth)
            this.maxWidth = this.bounds[i].width();
          i++;
          this.textPaint.getTextBounds(this.lines[i], 0, this.lines[i].length(), this.bounds[i]);
          
        }
      }
      int i4 = i2 + Math.abs(this.bounds[i3].top);
      this.lines[i3] = this.lines[i3].trim();
      int i5 = 0;
      if (this.bounds[i3].left < 0)
        i5 = this.bounds[i3].left;
      paramCanvas.drawText(this.lines[i3], i1 - i5, i4, this.textPaint);
      i2 = j + (i4 + this.bounds[i3].bottom);
    }
  }

  protected void onMeasure(int paramInt1, int paramInt2)
  {
    Rect localRect = getNodeBounds();
    setMeasuredDimension(localRect.right, localRect.bottom);
  }
}

/* Location:           D:\APKtoJava_RC2\tools\classes-dex2jar.jar
 * Qualified Name:     com.qdvsoftworks.schematicmind.nodes.OvalNode
 * JD-Core Version:    0.6.0
 */